/*
 * Copyright 2010 - 2011, The PLDesktop Development Team
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */

#include "commandline.h"

#include <kerneldebugconsole.h>

PLCommandline::PLCommandline(const char *commandline) {
	int i = 0;
	do {
		if(commandline[i - 1] == '\0') {
			break;
		}
		if(commandline[i] == '-' && commandline[i + 1] == '-') {
			if(compare(commandline, i + 2, "kerneldebug")) {
				m_kernelDebug = true;
				i = i + 2 + 11;
			}
			if(compare(commandline, i + 2, "nointerruptdetails")) {
				m_noInterruptDetails = true;
				i = i + 2 + 18;
			}
		}
		i++;
	} while(true);
	PLKernelDebugConsole::instance().printf("\nCommandline: kerneldebug: %s nointerruptdetails: %s",
                                            m_kernelDebug ? "true" : "false",
                                            m_noInterruptDetails ? "true" : "false");
}

bool PLCommandline::compare(const char *commandline, int pos, const char *with) {
	int i = pos;
	do {
		if(with[i - pos] == '\0') {
			break;
		}
		if(commandline[i] == '\0') {
			return false;
		}
		if(commandline[i] != with[i - pos]) {
			return false;
		}
		i++;
	} while(true);
	return true;
}
